
function CheckRequiredFields(f) {
   var sFieldValue = "";
   var iIndex = 0;
   var iElement = 0;
   var iRadio = 0;
   var iCheck = 0;
   
   // Retrieve the list of field names and labels
   var aFieldList = f.valFieldList.value.split(",");
   
   // Loop through the list of fields
   for (iIndex = 0; iIndex < aFieldList.length; iIndex++) {
   //alert(    "Validating field " + aFieldList[iIndex + 1] + " ...");
     //   alert(f.elements.length)
      // Inform the user of what's happening
      window.status = "Validating field " + aFieldList[iIndex + 1] + " ...";

      // Loop through all elements in the form to find the field
      for (iElement = 0; iElement < f.elements.length; iElement++) {
         // Check whether the selected element is a required field
//alert(f.elements[iElement].name + "--> " +  aFieldList[iIndex] )
         if (f.elements[iElement].name == aFieldList[iIndex]) {
            // Check whether the field contains a value or not

            switch (f.elements[iElement].type) {
               // Text fields
               case "text" :
                  sFieldValue = f.elements[iElement].value;
                  break;
               // Text areas
               case "textarea" :
                  sFieldValue = f.elements[iElement].value;
                  break;
               // Listboxes
               case "select-one" :
                  if (f.elements[iElement].selectedIndex == 0) {
                     sFieldValue = "";
                  } else {
                     sFieldValue = String(f.elements[iElement].selectedIndex);
                  }
                  break;
               // Checkboxes
               case "checkbox" :
                  for (iCheck = 0; iCheck < f.elements[aFieldList[iIndex]].length; iCheck++) {
                     if (f.elements[iElement + iCheck].checked == false) {
                        sFieldValue = "";
                     } else {
                        sFieldValue = String(f.elements[iElement + iCheck].value);
                        break;
                     }
                  }
                  break;
               // Radiobuttons
               case "radio" :
                  for (iRadio = 0; iRadio < f.elements[aFieldList[iIndex]].length; iRadio++) {
                     if (f.elements[iElement + iRadio].checked == false) {
                        sFieldValue = "";
                     } else {
                        sFieldValue = String(f.elements[iElement + iRadio].value);
                        break;
                     }
                  }
                  break;
            }

            // Warn the user that the selected field is a required field
            if (sFieldValue == "") {
               alert(aFieldList[iIndex+1] + " is a required field. Make sure that " +
               aFieldList[iIndex+1] + " and all other required fields are filled out before Submitting Idea");
               f.elements[iElement].focus();
               return false;
            }
            break;
         }
      }
      iIndex++;
   }
   return true;
}

function QuerySave(f){
return CheckRequiredFields(f);
}

function insertEmoticon(number)
{
	//insert emoticon in comments field
	var current = document.frmWComment.comBody.value;
	this.number = number;
	document.frmWComment.comBody.value = current + " !em" + number + "! ";
	document.frmWComment.comBody.focus();
}


function maxArray( arr ) {
	// this function calculates the maximum value in the associative array
	var max = 0;
	for(var i in arr){
  	    if (arr[i] > max)
  	    		max = arr[i];
  	}
  	return max;
}

function minArray( arr ) {
	// this function calculates the minimum value in the associative array
	var min;
	var count = 0;
	for(var i in arr){
		// initialize minimum value with first value of associative array
		if (count==0)
			min = arr[i];
		if (arr[i] < min)
  	    		min = arr[i];
  	    	count++;
  	}
  	return min;
}

